// OrderServiceImpl.java
package com.example.gamestore.service.Impl;

import com.example.gamestore.mapper.OrderMapper;
import com.example.gamestore.pojo.Order;
import com.example.gamestore.service.OrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Resource
    private OrderMapper orderMapper;

    @Override
    public Order createOrder(Order order) {
        try {
            order.setCreateTime(new Date()); // 设置创建时间
            int rows = orderMapper.createOrder(order);
            if (rows > 0) {
                return order;
            }
        } catch (Exception e) {
            // 记录日志
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Order> getOrdersByUserId(Long userId) {
        List<Order> orders = orderMapper.getOrdersByUserId(userId);
        for (Order order : orders) {
            System.out.println("查询到的订单: " + order);
        }
        return orders;
    }
    @Override
    public List<Order> getAllOrders() {
        return orderMapper.getAllOrders();
    }

    @Override
    public Order getOrderById(Long id) {
        return orderMapper.getOrderById(id);
    }

    @Override
    public int updateOrder(Order order) {
        return orderMapper.updateOrder(order);
    }

    @Override
    public int deleteOrder(Long id) {
        return orderMapper.deleteOrder(id);
    }



}